@echo off
echo Uninstalling Log Server Windows Service...
echo.

:: Check if Node.js is installed
node --version >nul 2>&1
if %errorlevel% neq 0 (
    echo Error: Node.js is not installed or not in PATH
    echo Please install Node.js first: https://nodejs.org/
    pause
    exit /b 1
)

:: Check if node-windows is available
npm list node-windows >nul 2>&1
if %errorlevel% neq 0 (
    echo Warning: node-windows is not installed
    echo Installing node-windows...
    npm install node-windows
    if %errorlevel% neq 0 (
        echo Error: Failed to install node-windows
        pause
        exit /b 1
    )
)

:: Run the service uninstallation script
echo Running service uninstallation...
node uninstall-windows-service.js

if %errorlevel% equ 0 (
    echo.
    echo Service uninstallation completed successfully!
    echo The LogServer service has been removed from Windows services.
) else (
    echo.
    echo Service uninstallation failed!
)

pause